const Router = require('koa-router');
const admin = new Router();
const bodyparser = require('koa-bodyparser');


//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
    database: 'running',
    user: 'run',
    port: 5432,
    host: '82.157.94.115',
    password: 'z12345678',
    max: 2
})





admin.post('/zhregister', async ctx => {
    let { username, password } = ctx.request.body;
    console.log('用户名', username);
    console.log('密码', password);
    function makeId() {
        let id = Math.random().toString(16).substring(2);
        let id2 = Math.random().toString(16).substring(2);
        return (id + id2).substring(0, 12);
    }

    let insertPostgresql = `insert into login (openid,username, password) values ($1,'${username}', '${password}')`

    let result = psql.query(insertPostgresql, [makeId()]);
    if (result.rowCount > 0) {
        ctx.body = {
            msg: "注册成功",
            openid: openid,
            username: username,
            password: password
        }
    }







}




)

module.exports = admin;

